package edu.uaskl.jqf.model.gates;

import edu.uaskl.jqf.model.gates.util.BaseGate;
import edu.uaskl.jqf.model.matrix.MatrixComplex;

public class DeutschBlackBox extends BaseGate {
    public static final DeutschBlackBox exampleConstant = new DeutschBlackBox(new MatrixComplex(new double[][] { { 0, 1, 0, 0 }, { 1, 0, 0, 0 },
            { 0, 0, 0, 1 }, { 0, 0, 1, 0 } }));
    public static final DeutschBlackBox exampleBalanced = new DeutschBlackBox(new ControlledU(Not.size2).getInstance());

    private final MatrixComplex matrix;

    public DeutschBlackBox(final MatrixComplex matrix) {
        if (!matrix.isSize(4, 4))
            throw new IllegalArgumentException("Blackbox must be size 4x4");
        if (!matrix.isUnitary())
            throw new IllegalArgumentException("Blackbox must be unitary");
        this.matrix = matrix;
    }

    @Override
    public MatrixComplex getSize(final int size) {
        if (size == 4)
            return matrix;
        throw new IllegalArgumentException("Size not supported at the moment");
    }

    @Override
    public MatrixComplex getInstance() {
        return matrix;
    }
}
